// 社会评价指标评分类型
var DemocracyScore = Ext.data.Record.create([{
	name : 'id',
	mapping : 'id',
	type : 'int'
}, {
	name : 'symbol',
	mapping : 'symbol',
	type : 'string'
},{
	name : 'remark',
	mapping : 'remark',
	type : 'string'
}, {
	name : 'point',
	mapping : 'point',
	type : 'float'
},{
	name : 'ordering',
	mapping : 'ordering',
	type : 'float'
}, {
	name : 'year',
	mapping : 'year',
	type : 'int'
}]);

var ds_democracyscore_select = new Ext.data.Store({
	proxy : new Ext.data.HttpProxy({
		url : '/supervise/biz/democracyscore/findAllDemocracyScore.action'
	}),
	autoLoad: true,
	reader : new Ext.data.JsonReader({
		root : 'root',
		successProperty :'success'
	}, [{
		name : 'id',
		type : 'int'
	}, {
		name : 'symbol',
		type : 'string'
	},{
		name : 'remark',
		type : 'string'
	},{
		name : 'point',
		type : 'string'
	},{
		name : 'ordering',
		type : 'string'
	},{
		name : 'year',
		mapping : 'year',
		type : 'int'
	}])
});

var sm = new Ext.grid.RowNumberer();
var cm_democracyscore = new Ext.grid.ColumnModel([
	new Ext.grid.RowNumberer({header : '序号', width : 40, dataIndex: 'id'}),
	{id: 'symbol',header: "等级符号", width: 100, sortable: true, dataIndex: 'symbol'},
	{id: 'remark',header: "符号说明", width: 300, sortable: true, dataIndex: 'remark'},
    {id: 'point',header: "代表分值", width: 80, sortable: true, dataIndex: 'point'},
    {id: 'ordering',header: "排序", width: 80, hidden: true, dataIndex: 'ordering'},
    {id: 'year',header: "考核年度", width: 120, dataIndex: 'year'}
]);

cm_democracyscore.defaultSortable = false;
var window_add_democracyscore = new Ext.Window({
			title : '添加社会评价指标评分类型',
			width : 480,
			height : 640,
			resizable : false,
			autoHeight : true,
			modal : true,
			closeAction : 'hide',
			listeners : {
				'hide' : function() {
					this.setTitle('添加社会评价指标评分类型');
					Ext.getCmp("form_add_democracyscore").getForm().reset();
				}
			},
			items : [new Ext.FormPanel({
						id : 'form_add_democracyscore',
						labelWidth : 100,
						labelAlign : 'right',
						url : '/supervise/biz/democracyscore/saveDemocracyScore.action',
						method : 'post',
						border : false,
						baseCls : 'x-plain',
						bodyStyle : 'padding:5px 5px 0',
						defaults : {
							anchor : '90%',
							width : 360,
							msgTarget : 'side' // 验证信息显示右边
						},
						defaultType : 'textfield',
						items : [{
									xtype : 'hidden',
									name : 'democracyScore.id'
								}, {
									fieldLabel : '<span style="color: red">*&nbsp;</span>等级符号',
									name : 'democracyScore.symbol',
									allowBlank : false,
									maxLength : 200
								},{
									xtype : 'textarea',
									fieldLabel : '<span style="color: red">*&nbsp;</span>符号说明',
									name : 'democracyScore.remark',
									allowBlank : false,
									maxLength : 200
								}, {
									xtype : 'numberfield',
									fieldLabel : '<span style="color: red">*&nbsp;</span>代表分值',
									name : 'democracyScore.point',
									allowBlank : false,
									format : 'Y-m-d'
								},{
									xtype : 'hidden',
									name : 'democracyScore.ordering'
								}, {
									xtype : 'combo',
									fieldLabel : '<span style="color: red">*&nbsp;</span>考核年度',
									hiddenName : 'democracyScore.year',
									mode : 'local',
									store : store_year,
									valueField : 'value',
									displayField : 'text',
									value: check_year,
									selectOnFocus : true,
									editable : false,
									allowBlank : false,
									readOnly : true,
									triggerAction : 'all',
									emptyText : '请选择考核年度'
								}],
						buttonAlign : 'center',
						minButtonWidth : 60,
						buttons : [{
									text : '添加',
									handler : function(btn) {
										var frm = Ext.getCmp("form_add_democracyscore").getForm();
										if (frm.isValid()) {
											btn.disable();
											var cnfield = frm.findField('democracyScore.symbol');
											frm.submit({
														waitTitle : '请稍候',
														waitMsg : '正在提交表单数据,请稍候...',
														success : function(form, action) {
															var store = grid_democracyscore.getStore();
															var democracyscore = new DemocracyScore({
																		id : action.result.id,
																		symbol : cnfield.getValue(),
																		remark : form.findField('democracyScore.remark').getValue(),
																		point : form.findField('democracyScore.point').getValue(),
																		ordering : form.findField('democracyScore.ordering').getValue(),
																		year : form.findField('democracyScore.year').getValue()
																	});
															store.insert(0, [democracyscore]);
															grid_democracyscore.getView().refresh();
															btn.enable();
															form.reset();
															window_add_democracyscore.hide();
														},
														failure : function() {
															Ext.Msg.show({
																		title : '错误提示',
																		msg : '"' + cnfield.getValue() + '" ' + '名称可能已经存在!',
																		buttons : Ext.Msg.OK,
																		fn : function() {
																			cnfield.focus(true);
																			btn.enable();
																		},
																		icon : Ext.Msg.ERROR
																	});
														}
													});
										}
									}
								}, {
									text : '重置',
									handler : function() {
										Ext.getCmp("form_add_democracyscore").getForm().reset();
									}
								}, {
									text : '取消',
									handler : function() {
										window_add_democracyscore.hide();
									}
								}]
					})]
		});
		
var window_edit_democracyscore = new Ext.Window({
			title : '修改社会评价指标评分类型',
			width : 480,
			height : 640,
			resizable : false,
			autoHeight : true,
			modal : true,
			closeAction : 'hide',
			listeners : {
				'hide' : function() {
					this.setTitle('修改社会评价指标评分类型');
					Ext.getCmp("form_edit_democracyscore").getForm().reset();
				}
			},
			items : [new Ext.FormPanel({
						id : 'form_edit_democracyscore',
						labelWidth : 100,
						labelAlign : 'right',
						url : '/supervise/biz/democracyscore/saveDemocracyScore.action',
						method : 'post',
						border : false,
						baseCls : 'x-plain',
						bodyStyle : 'padding:5px 5px 0',
						defaults : {
							anchor : '90%',
							width : 360,
							msgTarget : 'side' // 验证信息显示右边
						},
						defaultType : 'textfield',
						items : [{
									xtype : 'hidden',
									name : 'democracyScore.id'
								}, {
									fieldLabel : '<span style="color: red">*&nbsp;</span>等级符号',
									name : 'democracyScore.symbol',
									allowBlank : false,
									maxLength : 200
								},{
									xtype : 'textarea',
									fieldLabel : '<span style="color: red">*&nbsp;</span>符号说明',
									name : 'democracyScore.remark',
									allowBlank : false,
									maxLength : 200
								}, {
									xtype : 'numberfield',
									fieldLabel : '<span style="color: red">*&nbsp;</span>代表分值',
									name : 'democracyScore.point',
									allowBlank : false,
									format : 'Y-m-d'
								},{
									xtype : 'hidden',
									name : 'democracyScore.ordering'
								}, {
									xtype : 'combo',
									fieldLabel : '<span style="color: red">*&nbsp;</span>考核年度',
									hiddenName : 'democracyScore.year',
									mode : 'local',
									store : store_year,
									valueField : 'value',
									displayField : 'text',
									value: check_year,
									selectOnFocus : true,
									editable : false,
									allowBlank : false,
									readOnly : true,
									triggerAction : 'all',
									emptyText : '请选择考核年度'
								}],
						buttonAlign : 'center',
						minButtonWidth : 60,
						buttons : [{
									text : '修改',
									handler : function(btn) {
										var frm = Ext.getCmp("form_edit_democracyscore").getForm();
										if (frm.isValid()) {
											btn.disable();
											var cnfield = frm.findField('democracyScore.symbol');
											frm.submit({
														waitTitle : '请稍候',
														waitMsg : '正在提交表单数据,请稍候...',
														success : function(form, action) {
															var record = grid_democracyscore.getSelectionModel().getSelected();
															// set value
															record.set("symbol", frm.findField('democracyScore.symbol').getValue());
															record.set("remark", frm.findField('democracyScore.remark').getValue());
															record.set("point", frm.findField('democracyScore.point').getValue());
															record.set("ordering", frm.findField('democracyScore.ordering').getValue());
															record.set("year", frm.findField('democracyScore.year').getValue());
															record.commit();
															frm.reset();
															btn.enable();
															window_edit_democracyscore.hide();
														},
														failure : function() {
															Ext.Msg.show({
																		title : '错误提示',
																		msg : '"' + cnfield.getValue() + '" ' + '名称可能已经存在!',
																		buttons : Ext.Msg.OK,
																		fn : function() {
																			cnfield.focus(true);
																			btn.enable();
																		},
																		icon : Ext.Msg.ERROR
																	});
														}
													});
										}
									}
								}, {
									text : '取消',
									handler : function() {
										window_edit_democracyscore.hide();
									}
								}]
					})]
		});
var btn_add_democracyscore = new Ext.Button({
			text : '添加',
			iconCls : 'icon-add',
			handler : function() {
				window_add_democracyscore.show();
			}
		});
var btn_edit_democracyscore = new Ext.Button({
			text : '修改',
			iconCls : 'icon-edit',
			handler : function() {
				if (!grid_democracyscore.checkOne()) {
					return;
				}
				window_edit_democracyscore.show(this);
				var record = grid_democracyscore.getSelectionModel().getSelected();
				var frm = Ext.getCmp("form_edit_democracyscore").getForm();
				// set value
				frm.findField('democracyScore.id').setValue(record.get("id"));
				frm.findField('democracyScore.symbol').setValue(record.get("symbol"));
				frm.findField('democracyScore.remark').setValue(record.get("remark"));
				frm.findField('democracyScore.point').setValue(record.get("point"));
				frm.findField('democracyScore.ordering').setValue(record.get("ordering"));
				frm.findField('democracyScore.year').setValue(record.get("year"));
			}
		});
var btn_del_democracyscore = new Ext.Button({
			text : '删除',
			iconCls : 'icon-del',
			handler : function() {
				var record = grid_democracyscore.getSelectionModel().getSelected();
				if (record) {
					Ext.Msg.confirm('确认删除', '你确定删除该条记录?', function(btn) {
								if (btn == 'yes') {
									Ext.Ajax.request({
												url : '/supervise/biz/democracyscore/deleteDemocracyScore.action',
												params : {
													id : record.data.id
												},
												success : function() {
													grid_democracyscore.getStore().remove(record);
													grid_democracyscore.getView().refresh();
												},
												failure : function() {
													Ext.Msg.show({
																title : '错误提示',
																msg : '删除时发生错误!',
																buttons : Ext.Msg.OK,
																icon : Ext.Msg.ERROR
															});
												}
											});
								}
							});
				}
			}
		});
var btn_search_democracyscore = new Ext.Button({
	text : '查询',
	iconCls : 'icon-search',
	handler : function() {
		grid_democracyscore.render();
		ds_democracyscore.load();
	}
});

var ds_democracyscore = new Ext.data.Store({
	proxy : new Ext.data.HttpProxy({
		url : '/supervise/biz/democracyscore/findAllDemocracyScore.action'
	}),
	autoLoad: true,
	reader : new Ext.data.JsonReader({
		root : 'root',
		successProperty :'success'
	}, [{
		name : 'id',
		type : 'int'
	}, {
		name : 'symbol',
		type : 'string'
	},{
		name : 'remark',
		type : 'string'
	},{
		name : 'point',
		type : 'string'
	},{
		name : 'ordering',
		type : 'string'
	},{
		name : 'year',
		type : 'int'
	}])
});

var grid_democracyscore = new Ext.grid.GridPanel({
			title : '社会评价指标评分类型',
			iconCls : 'icon-grid',
			loadMask : {
				msg : '数据加载中...'
			},
			viewConfig : {
				forceFit : true
			},
			region : 'center',
			cm : cm_democracyscore,
			sm : new Ext.grid.RowSelectionModel({
						singleSelect : true
					}),
			store : ds_democracyscore,
			autoExpandColumn : 'symbol',
			tbar : [btn_add_democracyscore, '-', btn_edit_democracyscore, '-', btn_del_democracyscore, '-', btn_search_democracyscore],
			bbar : new Ext.PagingToolbar({
						pageSize : 20,
						store : ds_democracyscore,
						displayInfo : false,
						displayMsg : '第 {0} - {1} 条  共 {2} 条',
						refreshText : "刷新",
						emptyMsg : "没有记录"
					}),
			// 检测至少选择一个
			checkOne : function() {
				var selections = this.getSelectionModel().getSelections();
				if (selections.length == 0) {
					Ext.MessageBox.alert("提示", "请选择一条的记录！");
					return false;
				} else if (selections.length != 1) {
					Ext.MessageBox.alert("提示", "不能选择多行！");
					return false;
				}
				return true;
			},

			// 检测必须选择一个
			checkMany : function() {
				var selections = this.getSelectionModel().getSelections();
				if (selections.length == 0) {
					Ext.MessageBox.alert("提示", "请至少选择一条的记录！");
					return false;
				}
				return true;
			},
			listeners : {
				'render' : function(e) {
					ds_democracyscore.load();
				}
			}

		});

var p_democracyscore = {
	id : 'democracyscore-panel',
	border : false,
	layout : 'border',
	items : [grid_democracyscore]
};